<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>codeedit</title>
  <uieip type="file" value="inc" src="/yqwin/easyui/include.txt" cache="true" minute="1440"></uieip>
  <uieip type="file" value="css" src="/yqwin/css/yqwin.min" cache="false"></uieip>
  <uieip type="file" value="js" src="/yqwin/data/yqwin.min" cache="false"></uieip>
  <!-- <script src="/scripts/ace/ace.js" type="text/javascript" charset="utf-8"></script> -->
</head>

<body>
  <a href="/scripts/editor.md/lib/codemirror/index.html" target="_blank">codemirror</a>
  <a href="/scripts/editor.md/examples/index.html" target="_blank">editor.md</a>

  <p></p>
  <a href="#" id="btn_show" class="easyui-linkbutton" data-options="" onclick="javascript:show()">show</a>
  <p></p>
  <h1>codeedit</h1>
  <div id="editor" style="width:100%;height:400px;">some text</div>
  <p></p>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:setValue()">setValue</a>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:getValue()">getValue</a>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:getData()">getData</a>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:clearun()">clearun</a>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:disable()">disable</a>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:enable()">enable</a>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:destroy()">destroy</a>
  <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:init()">init</a>
  <script>
    
    $(function () {
      $("#editor").yqCodeEdit({
        types: ["text", "html", "json", "js"],
        type: "json",
        value: JSON.stringify(v_json,null,3),
        });
    });

    var v_json = {
        name:"张三",
        age:18,
        sex:"男"
    };

    var v = `var a=1;
var b=2;`;
    function setValue() {
      $("#editor").yqCodeEdit("setValue", v);
    }

    function getValue() {
      var val = $("#editor").yqCodeEdit("getValue");
      if (val == "") {
        console.log("空");
      }
      else if (val == null) {
        console.log("null");
      }
      console.log("getValue", val);
    }

    function getData() {
      var val = $("#editor").yqCodeEdit("getData");
      console.log("getData", val);
    }

    function clearun() {
      $("#editor").yqCodeEdit("clear");
    }

    function disable() {
      $("#editor").yqCodeEdit("disable");
    }
    function enable() {
      $("#editor").yqCodeEdit("enable");
    }

    function destroy() {
      $("#editor").yqCodeEdit("destroy");
    }

    function init() {
      $("#editor").yqCodeEdit({
        type: ["html"],
        value: "<p>aaaaaaaaa</p>"
      });
    }

    var b_value = {
      type: "html",
      value: "<p>1111111111</p>"
    }
    function show() {
      var $pp = $("#btn_show");
      var prevent_e = $.getPreventDefault($pp[0]);
      prevent_e.id = $pp.attr("id");
      prevent_e.options = {};

      var mdiinfo = $.yqGetWindParams();

      var show_pops = {
        prevent_e: prevent_e,
        mdiinfo: mdiinfo,

        width: 600,
        height: 420,
        types: ["html", "js", "css"],
        //types: ["html"],
        type: b_value.type,
        value: b_value.value,
        isEdit: true,

        callback: function (value) {
          b_value = value;
        }
      };

      if (window.top == window.self) {
        $.yqCodePopEdit(show_pops);
      }
      else {
        window.top.$.yqCodePopEdit(show_pops);
      }
    }
  </script>
</body>

</html>